package com.bjqg.bjqg01.bjqg.activity.longrange.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.ActionMode;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.bjqg.bjqg01.bjqg.R;
import com.bjqg.bjqg01.bjqg.activity.BaseActivity;
import com.bjqg.bjqg01.bjqg.activity.longrange.adapter.ChoiceAdapter;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.ChoiceBean;
import com.bjqg.bjqg01.bjqg.activity.longrange.bean.MultipleBean;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by bjqg01 on 2018/9/12.
 */

public class ChoiceActivity extends BaseActivity {

    @BindView(R.id.lv_dx)
    ListView lvDx;
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.tv_top_title_drawer)
    TextView tvTopTitleDrawer;
    @BindView(R.id.tv_search_top_drawer)
    TextView tvSearchTopDrawer;
    @BindView(R.id.btn_send)
    Button btnSend;

    List<ChoiceBean> choicelist = new ArrayList<>();
    ChoiceAdapter adapter;
    List<MultipleBean> multiplist = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_choice);
        ButterKnife.bind(this);
        initdate();
    }

    private void initdate() {
        tvTopTitleDrawer.setText("检测项目（多选）");
        tvSearchTopDrawer.setVisibility(View.INVISIBLE);

        for (int i = 0; i < 20; i++) {
            choicelist.add(new ChoiceBean("我是" + i, "" + i, false, i));
        }

        adapter = new ChoiceAdapter(this, choicelist);
        lvDx.setAdapter(adapter);

        adapter.setOnItemClickListener(new ChoiceAdapter.onItemClickListener() {
            @Override
            public void onItem(int position) {
                choicelist.get(position).setIsclick(true);
                adapter.notifyDataSetChanged();
            }
        });

    }

    @OnClick({R.id.back, R.id.btn_send})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.btn_send://保存

                for (int i = 0; i < choicelist.size(); i++) {
                    if (choicelist.get(i).isclick()) {
                        multiplist.add(new MultipleBean(choicelist.get(i).getName(), choicelist.get(i).getId(),choicelist.get(i).getPrice()));
                    }
                }

                EventBus.getDefault().post(multiplist);
                finish();

                break;
        }
    }


}
